cmake_minimum_required(VERSION 3.15.7)
project(datenaro)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

find_package(Crow REQUIRED)
include_directories(${Crow_INCLUDE_DIRS})

find_package(OpenSSL REQUIRED)
include_directories(${OpenSSL_INCLUDE_DIRS})

find_package(SQLite3 REQUIRED)
include_directories(${SQLite3_INCLUDE_DIRS})

find_package(nlohmann_json REQUIRED)
include_directories(${nlohmann_json_INCLUDE_DIRS})

find_package(ICU REQUIRED)
include_directories(${ICU_INCLUDE_DIRS})

set(CMAKE_INCLUDE_CURRENT_DIR ON)

file(GLOB SOURCES
    ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/database/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/database/migrations/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/database/data_elements/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/api/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/session/*.cpp
)

file(GLOB COMMON_SOURCES
    ${CMAKE_SOURCE_DIR}/src/common/api/server.cpp
    ${CMAKE_SOURCE_DIR}/src/common/elements/*.cpp
    ${CMAKE_SOURCE_DIR}/src/common/log/log.cpp
    ${CMAKE_SOURCE_DIR}/src/common/config/config.cpp
    ${CMAKE_SOURCE_DIR}/src/common/more/uuid.cpp
    ${CMAKE_SOURCE_DIR}/src/common/more/sha.cpp
    ${CMAKE_SOURCE_DIR}/src/common/more/json.cpp
    ${CMAKE_SOURCE_DIR}/src/common/more/string.cpp
)

add_executable(
    ${PROJECT_NAME}
    ${SOURCES}
    ${COMMON_SOURCES}
)

# Уровень логирования сообщений из библиотеки crow:
# 0 -- Debug
# 1 -- Info
# 2 -- Warning
# 3 -- Error
# 4 -- Critical
target_compile_definitions(
    ${PROJECT_NAME}
    PRIVATE
    CROW_LOG_LEVEL=2
)

target_include_directories(
    ${PROJECT_NAME}
    PUBLIC
    ${CMAKE_SOURCE_DIR}/src
    ${CMAKE_SOURCE_DIR}/thirdparty/sqlite_modern_cpp
)

target_link_libraries(
    ${PROJECT_NAME}
    ${SQLite3_LIBRARIES}
    ${Boost_LIBRARIES}
    ${Crow_LIBRARIES}
    ${OpenSSL_LIBRARIES}
    ${nlohmann_json_LIBRARIES}
    ${ICU_LIBRARIES}
)

install(
    TARGETS ${PROJECT_NAME}
    DESTINATION ${CMAKE_SOURCE_DIR}/install/bin
)
